home *** CD-ROM | disk | FTP | other *** search
/ APDL Other Worlds / APDL Other Worlds Collection.iso / SF3000 / Extras / !SFskyedit / s / Render
Encoding:
Text File  |  2003-10-16  |  5.1 KB  |  192 lines

  1. ;
  2. ; SFskyedit - Star Fighter 3000 sky colours editor
  3. ; Sky renderer
  4. ; Copyright (C) 2001  Chris Bazley
  5. ;
  6. ; This program is free software; you can redistribute it and/or modify
  7. ; it under the terms of the GNU General Public Licence as published by
  8. ; the Free Software Foundation; either version 2 of the Licence, or
  9. ; (at your option) any later version.
  10. ;
  11. ; This program is distributed in the hope that it will be useful,
  12. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ; GNU General Public Licence for more details.
  15. ;
  16. ; You should have received a copy of the GNU General Public Licence
  17. ; along with this program; if not, write to the Free Software
  18. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. ;
  20.  
  21. ; Original version by Fednet Software for Star Fighter 3000
  22. ; 13.07.01 CJB Modified for APCS-32 compliance
  23. ; 16.10.03 CJB Tweaked stack check to check for -ve rather than signed lower 
  24.  
  25. ; Routine to draw sky at variable height with variable shading
  26. ; Ver.4 With vertical clipping end (Height based) end-of-table check
  27. ; + Star start height at file +4
  28.  
  29. ; C prototype :
  30. ;   void sky_drawsky(int             height_scaler,
  31. ;                    SF_SkyColours **sky_address,
  32. ;                    void           *screen_address,
  33. ;                    int             scrstart_offset);
  34. ; -----------------------------------------------------------------------
  35.  
  36. ; a1 = height scaling number
  37. ; a2 = Address of pointer to sky colourtable to use
  38. ; a3 = Start of screen address
  39. ; a4 = offset from start of screen
  40.  
  41. ; File +0 = Min height of sky
  42. ; File +4 = Start height of star plot
  43. ;      +8+= Sky data
  44. ; -----------------------------------------------------------------------
  45.  
  46. ; Area name C$$code advisable if wanted to link with C output
  47.  
  48.         AREA    |C$$code|, CODE, READONLY
  49.  
  50.         EXPORT  |sky_drawsky|
  51.         IMPORT  |__rt_stkovf_split_small|
  52.  
  53. |sky_drawsky|
  54.                                        ; Create stack backtrace structure
  55.   MOV    ip, sp ; save current sp, ready to save as old sp
  56.   STMFD  sp!, {v1-v5, fp, ip, lr, pc}  ; as needed
  57.   SUB    fp, ip, #4 ; points to saved pc
  58.  
  59.   CMP   sp, sl                        ; Stack limit checking
  60.     BLMI   |__rt_stkovf_split_small|
  61.  
  62.   LDR a2,[a2]                 ; get pointer to sky colourtable
  63.  
  64.   MOV lr,a1,ASR#7
  65.   ADD lr,lr,lr,ASR#1
  66.   ADD lr,lr,#48               ; calculate height-related cap for colour index
  67.   CMP lr,#255
  68.     MOVGT lr,#255             ; (48 to 255)
  69.  
  70.   LDR v1,[a2],#8
  71.   ADD a1,a1,v1                ; Add initial height offset
  72.  
  73.   MOV v1,#0                   ; Current colour lookup
  74.  
  75.   CMP a4,#81920
  76.     BGE sky_clipsky           ; Clip for bottom of screen
  77.  
  78.   ADD a4,a3,a4                ; screen (right) store location
  79.   CMP a4,a3
  80.     LDMLEEA  fp, {v1-v5, fp, sp, pc} ; Clip for top of screen
  81.  
  82. sky_dolineagain
  83.   MOV v3,v1, ASR #10
  84.   ;TST a4,#2_100000
  85.   ;  SUBEQ v3,v3,#1     ; Don't understand this, and it is counter-productive
  86.  
  87.   CMP v3,lr
  88.     LDRGT v2,[a2,lr,ASL#2] ; cap colour lookup to R14 (height related)
  89.     LDRLE v2,[a2,v3,ASL#2] ; read word to plot
  90.  
  91.   MOV v3,v2 ; duplicate across four words (16 pixels)
  92.   MOV v4,v2
  93.   MOV v5,v2
  94.  
  95.   ; Store line backwards
  96.  
  97.   STMDA a4!,{v2-v5}
  98.   STMDA a4!,{v2-v5}
  99.   STMDA a4!,{v2-v5}
  100.   STMDA a4!,{v2-v5}
  101.   STMDA a4!,{v2-v5}
  102.   STMDA a4!,{v2-v5}
  103.   STMDA a4!,{v2-v5}
  104.   STMDA a4!,{v2-v5}
  105.   STMDA a4!,{v2-v5}
  106.   STMDA a4!,{v2-v5}
  107.   STMDA a4!,{v2-v5}
  108.   STMDA a4!,{v2-v5}
  109.   STMDA a4!,{v2-v5}
  110.   STMDA a4!,{v2-v5}
  111.   STMDA a4!,{v2-v5}
  112.   STMDA a4!,{v2-v5}
  113.   STMDA a4!,{v2-v5}
  114.   STMDA a4!,{v2-v5}
  115.   STMDA a4!,{v2-v5}
  116.   STMDA a4!,{v2-v5}
  117.  
  118.   CMP a4,a3
  119.     LDMLEEA  fp, {v1-v5, fp, sp, pc}
  120.  
  121.   ; Line is complete - now shift up colour bands
  122.  
  123.   ADD v1,v1,a1         ; the higher you are, the narrower the colour bands
  124.   SUBS a1,a1,a1,ASR#5  ; the later bands also change slower
  125.  
  126.   MOV v3,v1, ASR #10
  127.   ;TST a4,#2_100000
  128.   ;  SUBEQ v3,v3,#1   ; Don't understand this, and it is counter-productive
  129.  
  130.   CMP v3,lr
  131.     LDRGT v2,[a2,lr,ASL#2] ; cap colour lookup to R14 (height related)
  132.     LDRLE v2,[a2,v3,ASL#2] ; read word to plot
  133.   MOV v2,v2,ROR #8 ; prevent stripes in dithering
  134.  
  135.   MOV v3,v2  ; duplicate across four words (16 pixels)
  136.   MOV v4,v2
  137.   MOV v5,v2
  138.  
  139.   ; Store line backwards
  140.  
  141.   STMDA a4!,{v2-v5}
  142.   STMDA a4!,{v2-v5}
  143.   STMDA a4!,{v2-v5}
  144.   STMDA a4!,{v2-v5}
  145.   STMDA a4!,{v2-v5}
  146.   STMDA a4!,{v2-v5}
  147.   STMDA a4!,{v2-v5}
  148.   STMDA a4!,{v2-v5}
  149.   STMDA a4!,{v2-v5}
  150.   STMDA a4!,{v2-v5}
  151.   STMDA a4!,{v2-v5}
  152.   STMDA a4!,{v2-v5}
  153.   STMDA a4!,{v2-v5}
  154.   STMDA a4!,{v2-v5}
  155.   STMDA a4!,{v2-v5}
  156.   STMDA a4!,{v2-v5}
  157.   STMDA a4!,{v2-v5}
  158.   STMDA a4!,{v2-v5}
  159.   STMDA a4!,{v2-v5}
  160.   STMDA a4!,{v2-v5}
  161.  
  162.   ; Line is complete - now shift up colour bands
  163.   ADD v1,v1,a1,ASL#1
  164.   SUBS a1,a1,a1,ASR#4
  165.  
  166.   CMP a4,a3
  167.     BGT sky_dolineagain
  168.  
  169.   LDMEA  fp, {v1-v5, fp, sp, pc}
  170.  
  171.   ; -----------------------------------------------------------------------
  172.  
  173. sky_clipsky                      ; Clip sky for bottom of screen
  174.   ADD a4,a3,a4
  175.   ADD v2,a3,#81920
  176.  
  177. sky_clipskyagain
  178.   ADD v1,v1,a1
  179.   SUBS a1,a1,a1,ASR#5
  180.   SUB a4,a4,#320
  181.   CMP a4,v2
  182.     BLT sky_dolineagain
  183.  
  184.   ADD v1,v1,a1,ASL#1
  185.   SUBS a1,a1,a1,ASR#4
  186.   SUB a4,a4,#320
  187.   CMP a4,v2
  188.     BGE sky_clipskyagain
  189.   B sky_dolineagain
  190.  
  191.   END
  192.